home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1998 November / Freeware November 1998.img / dist / fw_elisp-manual-19.idb / usr / freeware / info / elisp-22.z / elisp-22 (.txt)
GNU Info File  |  1998-05-26  |  48KB  |  854 lines

  1. This is Info file elisp, produced by Makeinfo-1.63 from the input file
  2. elisp.texi.
  3.    This version is the edition 2.4.2 of the GNU Emacs Lisp Reference
  4. Manual.  It corresponds to Emacs Version 19.34.
  5.    Published by the Free Software Foundation 59 Temple Place, Suite 330
  6. Boston, MA  02111-1307  USA
  7.    Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996 Free Software
  8. Foundation, Inc.
  9.    Permission is granted to make and distribute verbatim copies of this
  10. manual provided the copyright notice and this permission notice are
  11. preserved on all copies.
  12.    Permission is granted to copy and distribute modified versions of
  13. this manual under the conditions for verbatim copying, provided that the
  14. entire resulting derived work is distributed under the terms of a
  15. permission notice identical to this one.
  16.    Permission is granted to copy and distribute translations of this
  17. manual into another language, under the above conditions for modified
  18. versions, except that this permission notice may be stated in a
  19. translation approved by the Foundation.
  20.    Permission is granted to copy and distribute modified versions of
  21. this manual under the conditions for verbatim copying, provided also
  22. that the section entitled "GNU General Public License" is included
  23. exactly as in the original, and provided that the entire resulting
  24. derived work is distributed under the terms of a permission notice
  25. identical to this one.
  26.    Permission is granted to copy and distribute translations of this
  27. manual into another language, under the above conditions for modified
  28. versions, except that the section entitled "GNU General Public License"
  29. may be included in a translation approved by the Free Software
  30. Foundation instead of in the original English.
  31. File: elisp,  Node: Buffer File Name,  Next: Buffer Modification,  Prev: Buffer Names,  Up: Buffers
  32. Buffer File Name
  33. ================
  34.    The "buffer file name" is the name of the file that is visited in
  35. that buffer.  When a buffer is not visiting a file, its buffer file name
  36. is `nil'.  Most of the time, the buffer name is the same as the
  37. nondirectory part of the buffer file name, but the buffer file name and
  38. the buffer name are distinct and can be set independently.  *Note
  39. Visiting Files::.
  40.  - Function: buffer-file-name &optional BUFFER
  41.      This function returns the absolute file name of the file that
  42.      BUFFER is visiting.  If BUFFER is not visiting any file,
  43.      `buffer-file-name' returns `nil'.  If BUFFER is not supplied, it
  44.      defaults to the current buffer.
  45.           (buffer-file-name (other-buffer))
  46.                => "/usr/user/lewis/manual/files.texi"
  47.  - Variable: buffer-file-name
  48.      This buffer-local variable contains the name of the file being
  49.      visited in the current buffer, or `nil' if it is not visiting a
  50.      file.  It is a permanent local, unaffected by
  51.      `kill-local-variables'.
  52.           buffer-file-name
  53.                => "/usr/user/lewis/manual/buffers.texi"
  54.      It is risky to change this variable's value without doing various
  55.      other things.  See the definition of `set-visited-file-name' in
  56.      `files.el'; some of the things done there, such as changing the
  57.      buffer name, are not strictly necessary, but others are essential
  58.      to avoid confusing Emacs.
  59.  - Variable: buffer-file-truename
  60.      This buffer-local variable holds the truename of the file visited
  61.      in the current buffer, or `nil' if no file is visited.  It is a
  62.      permanent local, unaffected by `kill-local-variables'.  *Note
  63.      Truenames::.
  64.  - Variable: buffer-file-number
  65.      This buffer-local variable holds the file number and directory
  66.      device number of the file visited in the current buffer, or `nil'
  67.      if no file or a nonexistent file is visited.  It is a permanent
  68.      local, unaffected by `kill-local-variables'.  *Note Truenames::.
  69.      The value is normally a list of the form `(FILENUM DEVNUM)'.  This
  70.      pair of numbers uniquely identifies the file among all files
  71.      accessible on the system.  See the function `file-attributes', in
  72.      *Note File Attributes::, for more information about them.
  73.  - Function: get-file-buffer FILENAME
  74.      This function returns the buffer visiting file FILENAME.  If there
  75.      is no such buffer, it returns `nil'.  The argument FILENAME, which
  76.      must be a string, is expanded (*note File Name Expansion::.), then
  77.      compared against the visited file names of all live buffers.
  78.           (get-file-buffer "buffers.texi")
  79.               => #<buffer buffers.texi>
  80.      In unusual circumstances, there can be more than one buffer
  81.      visiting the same file name.  In such cases, this function returns
  82.      the first such buffer in the buffer list.
  83.  - Command: set-visited-file-name FILENAME
  84.      If FILENAME is a non-empty string, this function changes the name
  85.      of the file visited in current buffer to FILENAME.  (If the buffer
  86.      had no visited file, this gives it one.)  The *next time* the
  87.      buffer is saved it will go in the newly-specified file.  This
  88.      command marks the buffer as modified, since it does not (as far as
  89.      Emacs knows) match the contents of FILENAME, even if it matched the
  90.      former visited file.
  91.      If FILENAME is `nil' or the empty string, that stands for "no
  92.      visited file".  In this case, `set-visited-file-name' marks the
  93.      buffer as having no visited file.
  94.      When the function `set-visited-file-name' is called interactively,
  95.      it prompts for FILENAME in the minibuffer.
  96.      See also `clear-visited-file-modtime' and
  97.      `verify-visited-file-modtime' in *Note Buffer Modification::.
  98.  - Variable: list-buffers-directory
  99.      This buffer-local variable records a string to display in a buffer
  100.      listing in place of the visited file name, for buffers that don't
  101.      have a visited file name.  Dired buffers use this variable.
  102. File: elisp,  Node: Buffer Modification,  Next: Modification Time,  Prev: Buffer File Name,  Up: Buffers
  103. Buffer Modification
  104. ===================
  105.    Emacs keeps a flag called the "modified flag" for each buffer, to
  106. record whether you have changed the text of the buffer.  This flag is
  107. set to `t' whenever you alter the contents of the buffer, and cleared
  108. to `nil' when you save it.  Thus, the flag shows whether there are
  109. unsaved changes.  The flag value is normally shown in the mode line
  110. (*note Mode Line Variables::.), and controls saving (*note Saving
  111. Buffers::.) and auto-saving (*note Auto-Saving::.).
  112.    Some Lisp programs set the flag explicitly.  For example, the
  113. function `set-visited-file-name' sets the flag to `t', because the text
  114. does not match the newly-visited file, even if it is unchanged from the
  115. file formerly visited.
  116.    The functions that modify the contents of buffers are described in
  117. *Note Text::.
  118.  - Function: buffer-modified-p &optional BUFFER
  119.      This function returns `t' if the buffer BUFFER has been modified
  120.      since it was last read in from a file or saved, or `nil'
  121.      otherwise.  If BUFFER is not supplied, the current buffer is
  122.      tested.
  123.  - Function: set-buffer-modified-p FLAG
  124.      This function marks the current buffer as modified if FLAG is
  125.      non-`nil', or as unmodified if the flag is `nil'.
  126.      Another effect of calling this function is to cause unconditional
  127.      redisplay of the mode line for the current buffer.  In fact, the
  128.      function `force-mode-line-update' works by doing this:
  129.           (set-buffer-modified-p (buffer-modified-p))
  130.  - Command: not-modified
  131.      This command marks the current buffer as unmodified, and not
  132.      needing to be saved.  With prefix arg, it marks the buffer as
  133.      modified, so that it will be saved at the next suitable occasion.
  134.      Don't use this function in programs, since it prints a message in
  135.      the echo area; use `set-buffer-modified-p' (above) instead.
  136.  - Function: buffer-modified-tick &optional BUFFER
  137.      This function returns BUFFER's modification-count.  This is a
  138.      counter that increments every time the buffer is modified.  If
  139.      BUFFER is `nil' (or omitted), the current buffer is used.
  140. File: elisp,  Node: Modification Time,  Next: Read Only Buffers,  Prev: Buffer Modification,  Up: Buffers
  141. Comparison of Modification Time
  142. ===============================
  143.    Suppose that you visit a file and make changes in its buffer, and
  144. meanwhile the file itself is changed on disk.  At this point, saving the
  145. buffer would overwrite the changes in the file.  Occasionally this may
  146. be what you want, but usually it would lose valuable information.  Emacs
  147. therefore checks the file's modification time using the functions
  148. described below before saving the file.
  149.  - Function: verify-visited-file-modtime BUFFER
  150.      This function compares what BUFFER has recorded for the
  151.      modification time of its visited file against the actual
  152.      modification time of the file as recorded by the operating system.
  153.      The two should be the same unless some other process has written
  154.      the file since Emacs visited or saved it.
  155.      The function returns `t' if the last actual modification time and
  156.      Emacs's recorded modification time are the same, `nil' otherwise.
  157.  - Function: clear-visited-file-modtime
  158.      This function clears out the record of the last modification time
  159.      of the file being visited by the current buffer.  As a result, the
  160.      next attempt to save this buffer will not complain of a
  161.      discrepancy in file modification times.
  162.      This function is called in `set-visited-file-name' and other
  163.      exceptional places where the usual test to avoid overwriting a
  164.      changed file should not be done.
  165.  - Function: visited-file-modtime
  166.      This function returns the buffer's recorded last file modification
  167.      time, as a list of the form `(HIGH . LOW)'.  (This is the same
  168.      format that `file-attributes' uses to return time values; see
  169.      *Note File Attributes::.)
  170.  - Function: set-visited-file-modtime &optional TIME
  171.      This function updates the buffer's record of the last modification
  172.      time of the visited file, to the value specified by TIME if TIME
  173.      is not `nil', and otherwise to the last modification time of the
  174.      visited file.
  175.      If TIME is not `nil', it should have the form `(HIGH . LOW)' or
  176.      `(HIGH LOW)', in either case containing two integers, each of
  177.      which holds 16 bits of the time.
  178.      This function is useful if the buffer was not read from the file
  179.      normally, or if the file itself has been changed for some known
  180.      benign reason.
  181.  - Function: ask-user-about-supersession-threat FILENAME
  182.      This function is used to ask a user how to proceed after an
  183.      attempt to modify an obsolete buffer visiting file FILENAME.  An
  184.      "obsolete buffer" is an unmodified buffer for which the associated
  185.      file on disk is newer than the last save-time of the buffer.  This
  186.      means some other program has probably altered the file.
  187.      Depending on the user's answer, the function may return normally,
  188.      in which case the modification of the buffer proceeds, or it may
  189.      signal a `file-supersession' error with data `(FILENAME)', in which
  190.      case the proposed buffer modification is not allowed.
  191.      This function is called automatically by Emacs on the proper
  192.      occasions.  It exists so you can customize Emacs by redefining it.
  193.      See the file `userlock.el' for the standard definition.
  194.      See also the file locking mechanism in *Note File Locks::.
  195. File: elisp,  Node: Read Only Buffers,  Next: The Buffer List,  Prev: Modification Time,  Up: Buffers
  196. Read-Only Buffers
  197. =================
  198.    If a buffer is "read-only", then you cannot change its contents,
  199. although you may change your view of the contents by scrolling and
  200. narrowing.
  201.    Read-only buffers are used in two kinds of situations:
  202.    * A buffer visiting a write-protected file is normally read-only.
  203.      Here, the purpose is to show the user that editing the buffer with
  204.      the aim of saving it in the file may be futile or undesirable.
  205.      The user who wants to change the buffer text despite this can do
  206.      so after clearing the read-only flag with `C-x C-q'.
  207.    * Modes such as Dired and Rmail make buffers read-only when altering
  208.      the contents with the usual editing commands is probably a mistake.
  209.      The special commands of these modes bind `buffer-read-only' to
  210.      `nil' (with `let') or bind `inhibit-read-only' to `t' around the
  211.      places where they change the text.
  212.  - Variable: buffer-read-only
  213.      This buffer-local variable specifies whether the buffer is
  214.      read-only.  The buffer is read-only if this variable is non-`nil'.
  215.  - Variable: inhibit-read-only
  216.      If this variable is non-`nil', then read-only buffers and read-only
  217.      characters may be modified.  Read-only characters in a buffer are
  218.      those that have non-`nil' `read-only' properties (either text
  219.      properties or overlay properties).  *Note Special Properties::,
  220.      for more information about text properties.  *Note Overlays::, for
  221.      more information about overlays and their properties.
  222.      If `inhibit-read-only' is `t', all `read-only' character
  223.      properties have no effect.  If `inhibit-read-only' is a list, then
  224.      `read-only' character properties have no effect if they are members
  225.      of the list (comparison is done with `eq').
  226.  - Command: toggle-read-only
  227.      This command changes whether the current buffer is read-only.  It
  228.      is intended for interactive use; don't use it in programs.  At any
  229.      given point in a program, you should know whether you want the
  230.      read-only flag on or off; so you can set `buffer-read-only'
  231.      explicitly to the proper value, `t' or `nil'.
  232.  - Function: barf-if-buffer-read-only
  233.      This function signals a `buffer-read-only' error if the current
  234.      buffer is read-only.  *Note Interactive Call::, for another way to
  235.      signal an error if the current buffer is read-only.
  236. File: elisp,  Node: The Buffer List,  Next: Creating Buffers,  Prev: Read Only Buffers,  Up: Buffers
  237. The Buffer List
  238. ===============
  239.    The "buffer list" is a list of all live buffers.  Creating a buffer
  240. adds it to this list, and killing a buffer deletes it.  The order of
  241. the buffers in the list is based primarily on how recently each buffer
  242. has been displayed in the selected window.  Buffers move to the front
  243. of the list when they are selected and to the end when they are buried.
  244. Several functions, notably `other-buffer', use this ordering.  A
  245. buffer list displayed for the user also follows this order.
  246.  - Function: buffer-list
  247.      This function returns a list of all buffers, including those whose
  248.      names begin with a space.  The elements are actual buffers, not
  249.      their names.
  250.           (buffer-list)
  251.                => (#<buffer buffers.texi>
  252.                    #<buffer  *Minibuf-1*> #<buffer buffer.c>
  253.                    #<buffer *Help*> #<buffer TAGS>)
  254.           
  255.           ;; Note that the name of the minibuffer
  256.           ;;   begins with a space!
  257.           (mapcar (function buffer-name) (buffer-list))
  258.               => ("buffers.texi" " *Minibuf-1*"
  259.                   "buffer.c" "*Help*" "TAGS")
  260.    The list that `buffer-list' returns is constructed specifically by
  261. `buffer-list'; it is not an internal Emacs data structure, and
  262. modifying it has no effect on the order of buffers.  If you want to
  263. change the order of buffers in the list, here is an easy way:
  264.      (defun reorder-buffer-list (new-list)
  265.        (while new-list
  266.          (bury-buffer (car new-list))
  267.          (setq new-list (cdr new-list))))
  268.    With this method, you can specify any order for the list, but there
  269. is no danger of losing a buffer or adding something that is not a valid
  270. live buffer.
  271.  - Function: other-buffer &optional BUFFER VISIBLE-OK
  272.      This function returns the first buffer in the buffer list other
  273.      than BUFFER.  Usually this is the buffer most recently shown in
  274.      the selected window, aside from BUFFER.  Buffers whose names start
  275.      with a space are not considered.
  276.      If BUFFER is not supplied (or if it is not a buffer), then
  277.      `other-buffer' returns the first buffer on the buffer list that is
  278.      not visible in any window in a visible frame.
  279.      If the selected frame has a non-`nil' `buffer-predicate'
  280.      parameter, then `other-buffer' uses that predicate to decide which
  281.      buffers to consider.  It calls the predicate once for each buffer,
  282.      and if the value is `nil', that buffer is ignored.  *Note X Frame
  283.      Parameters::.
  284.      If VISIBLE-OK is `nil', `other-buffer' avoids returning a buffer
  285.      visible in any window on any visible frame, except as a last
  286.      resort.   If VISIBLE-OK is non-`nil', then it does not matter
  287.      whether a buffer is displayed somewhere or not.
  288.      If no suitable buffer exists, the buffer `*scratch*' is returned
  289.      (and created, if necessary).
  290.  - Command: bury-buffer &optional BUFFER-OR-NAME
  291.      This function puts BUFFER-OR-NAME at the end of the buffer list
  292.      without changing the order of any of the other buffers on the list.
  293.      This buffer therefore becomes the least desirable candidate for
  294.      `other-buffer' to return.
  295.      If BUFFER-OR-NAME is `nil' or omitted, this means to bury the
  296.      current buffer.  In addition, if the buffer is displayed in the
  297.      selected window, this switches to some other buffer (obtained using
  298.      `other-buffer') in the selected window.  But if the buffer is
  299.      displayed in some other window, it remains displayed there.
  300.      If you wish to replace a buffer in all the windows that display
  301.      it, use `replace-buffer-in-windows'.  *Note Buffers and Windows::.
  302. File: elisp,  Node: Creating Buffers,  Next: Killing Buffers,  Prev: The Buffer List,  Up: Buffers
  303. Creating Buffers
  304. ================
  305.    This section describes the two primitives for creating buffers.
  306. `get-buffer-create' creates a buffer if it finds no existing buffer
  307. with the specified name; `generate-new-buffer' always creates a new
  308. buffer and gives it a unique name.
  309.    Other functions you can use to create buffers include
  310. `with-output-to-temp-buffer' (*note Temporary Displays::.) and
  311. `create-file-buffer' (*note Visiting Files::.).  Starting a subprocess
  312. can also create a buffer (*note Processes::.).
  313.  - Function: get-buffer-create NAME
  314.      This function returns a buffer named NAME.  It returns an existing
  315.      buffer with that name, if one exists; otherwise, it creates a new
  316.      buffer.  The buffer does not become the current buffer--this
  317.      function does not change which buffer is current.
  318.      An error is signaled if NAME is not a string.
  319.           (get-buffer-create "foo")
  320.                => #<buffer foo>
  321.      The major mode for the new buffer is set to Fundamental mode.  The
  322.      variable `default-major-mode' is handled at a higher level.  *Note
  323.      Auto Major Mode::.
  324.  - Function: generate-new-buffer NAME
  325.      This function returns a newly created, empty buffer, but does not
  326.      make it current.  If there is no buffer named NAME, then that is
  327.      the name of the new buffer.  If that name is in use, this function
  328.      adds suffixes of the form `<N>' to NAME, where N is an integer.
  329.      It tries successive integers starting with 2 until it finds an
  330.      available name.
  331.      An error is signaled if NAME is not a string.
  332.           (generate-new-buffer "bar")
  333.                => #<buffer bar>
  334.           (generate-new-buffer "bar")
  335.                => #<buffer bar<2>>
  336.           (generate-new-buffer "bar")
  337.                => #<buffer bar<3>>
  338.      The major mode for the new buffer is set to Fundamental mode.  The
  339.      variable `default-major-mode' is handled at a higher level.  *Note
  340.      Auto Major Mode::.
  341.      See the related function `generate-new-buffer-name' in *Note
  342.      Buffer Names::.
  343. File: elisp,  Node: Killing Buffers,  Next: Indirect Buffers,  Prev: Creating Buffers,  Up: Buffers
  344. Killing Buffers
  345. ===============
  346.    "Killing a buffer" makes its name unknown to Emacs and makes its
  347. text space available for other use.
  348.    The buffer object for the buffer that has been killed remains in
  349. existence as long as anything refers to it, but it is specially marked
  350. so that you cannot make it current or display it.  Killed buffers retain
  351. their identity, however; two distinct buffers, when killed, remain
  352. distinct according to `eq'.
  353.    If you kill a buffer that is current or displayed in a window, Emacs
  354. automatically selects or displays some other buffer instead.  This means
  355. that killing a buffer can in general change the current buffer.
  356. Therefore, when you kill a buffer, you should also take the precautions
  357. associated with changing the current buffer (unless you happen to know
  358. that the buffer being killed isn't current).  *Note Current Buffer::.
  359.    If you kill a buffer that is the base buffer of one or more indirect
  360. buffers, the indirect buffers are automatically killed as well.
  361.    The `buffer-name' of a killed buffer is `nil'.  You can use this
  362. feature to test whether a buffer has been killed:
  363.      (defun buffer-killed-p (buffer)
  364.        "Return t if BUFFER is killed."
  365.        (not (buffer-name buffer)))
  366.  - Command: kill-buffer BUFFER-OR-NAME
  367.      This function kills the buffer BUFFER-OR-NAME, freeing all its
  368.      memory for other uses or to be returned to the operating system.
  369.      It returns `nil'.
  370.      Any processes that have this buffer as the `process-buffer' are
  371.      sent the `SIGHUP' signal, which normally causes them to terminate.
  372.      (The basic meaning of `SIGHUP' is that a dialup line has been
  373.      disconnected.)  *Note Deleting Processes::.
  374.      If the buffer is visiting a file and contains unsaved changes,
  375.      `kill-buffer' asks the user to confirm before the buffer is killed.
  376.      It does this even if not called interactively.  To prevent the
  377.      request for confirmation, clear the modified flag before calling
  378.      `kill-buffer'.  *Note Buffer Modification::.
  379.      Killing a buffer that is already dead has no effect.
  380.           (kill-buffer "foo.unchanged")
  381.                => nil
  382.           (kill-buffer "foo.changed")
  383.           
  384.           ---------- Buffer: Minibuffer ----------
  385.           Buffer foo.changed modified; kill anyway? (yes or no) `yes'
  386.           ---------- Buffer: Minibuffer ----------
  387.           
  388.                => nil
  389.  - Variable: kill-buffer-query-functions
  390.      After confirming unsaved changes, `kill-buffer' calls the functions
  391.      in the list `kill-buffer-query-functions', in order of appearance,
  392.      with no arguments.  The buffer being killed is the current buffer
  393.      when they are called.  The idea is that these functions ask for
  394.      confirmation from the user for various nonstandard reasons.  If
  395.      any of them returns `nil', `kill-buffer' spares the buffer's life.
  396.  - Variable: kill-buffer-hook
  397.      This is a normal hook run by `kill-buffer' after asking all the
  398.      questions it is going to ask, just before actually killing the
  399.      buffer.  The buffer to be killed is current when the hook
  400.      functions run.  *Note Hooks::.
  401.  - Variable: buffer-offer-save
  402.      This variable, if non-`nil' in a particular buffer, tells
  403.      `save-buffers-kill-emacs' and `save-some-buffers' to offer to save
  404.      that buffer, just as they offer to save file-visiting buffers.  The
  405.      variable `buffer-offer-save' automatically becomes buffer-local
  406.      when set for any reason.  *Note Buffer-Local Variables::.
  407. File: elisp,  Node: Indirect Buffers,  Prev: Killing Buffers,  Up: Buffers
  408. Indirect Buffers
  409. ================
  410.    An "indirect buffer" shares the text of some other buffer, which is
  411. called the "base buffer" of the indirect buffer.  In some ways it is
  412. the analogue, for buffers, of a symbolic link among files.  The base
  413. buffer may not itself be an indirect buffer.
  414.    The text of the indirect buffer is always identical to the text of
  415. its base buffer; changes made by editing either one are visible
  416. immediately in the other.  This includes the text properties as well as
  417. the characters themselves.
  418.    But in all other respects, the indirect buffer and its base buffer
  419. are completely separate.  They have different names, different values of
  420. point, different narrowing, different markers and overlays (though
  421. inserting or deleting text in either buffer relocates the markers and
  422. overlays for both), different major modes, and different local
  423. variables.
  424.    An indirect buffer cannot visit a file, but its base buffer can.  If
  425. you try to save the indirect buffer, that actually works by saving the
  426. base buffer.
  427.    Killing an indirect buffer has no effect on its base buffer.  Killing
  428. the base buffer effectively kills the indirect buffer in that it cannot
  429. ever again be the current buffer.
  430.  - Command: make-indirect-buffer BASE-BUFFER NAME
  431.      This creates an indirect buffer named NAME whose base buffer is
  432.      BASE-BUFFER.  The argument BASE-BUFFER may be a buffer or a string.
  433.      If BASE-BUFFER is an indirect buffer, its base buffer is used as
  434.      the base for the new buffer.
  435.  - Function: buffer-base-buffer BUFFER
  436.      This function returns the base buffer of BUFFER.  If BUFFER is not
  437.      indirect, the value is `nil'.  Otherwise, the value is another
  438.      buffer, which is never an indirect buffer.
  439. File: elisp,  Node: Windows,  Next: Frames,  Prev: Buffers,  Up: Top
  440. Windows
  441. *******
  442.    This chapter describes most of the functions and variables related to
  443. Emacs windows.  See *Note Display::, for information on how text is
  444. displayed in windows.
  445. * Menu:
  446. * Basic Windows::           Basic information on using windows.
  447. * Splitting Windows::       Splitting one window into two windows.
  448. * Deleting Windows::        Deleting a window gives its space to other windows.
  449. * Selecting Windows::       The selected window is the one that you edit in.
  450. * Cyclic Window Ordering::  Moving around the existing windows.
  451. * Buffers and Windows::     Each window displays the contents of a buffer.
  452. * Displaying Buffers::      Higher-lever functions for displaying a buffer
  453.                               and choosing a window for it.
  454. * Choosing Window::        How to choose a window for displaying a buffer.
  455. * Window Point::            Each window has its own location of point.
  456. * Window Start::            The display-start position controls which text
  457.                               is on-screen in the window.
  458. * Vertical Scrolling::      Moving text up and down in the window.
  459. * Scrolling Hooks::         Hooks that run when you scroll a window.
  460. * Horizontal Scrolling::    Moving text sideways on the window.
  461. * Size of Window::          Accessing the size of a window.
  462. * Resizing Windows::        Changing the size of a window.
  463. * Coordinates and Windows:: Converting coordinates to windows.
  464. * Window Configurations::   Saving and restoring the state of the screen.
  465. File: elisp,  Node: Basic Windows,  Next: Splitting Windows,  Up: Windows
  466. Basic Concepts of Emacs Windows
  467. ===============================
  468.    A "window" in Emacs is the physical area of the screen in which a
  469. buffer is displayed.  The term is also used to refer to a Lisp object
  470. that represents that screen area in Emacs Lisp.  It should be clear
  471. from the context which is meant.
  472.    Emacs groups windows into frames.  A frame represents an area of
  473. screen available for Emacs to use.  Each frame always contains at least
  474. one window, but you can subdivide it vertically or horizontally into
  475. multiple nonoverlapping Emacs windows.
  476.    In each frame, at any time, one and only one window is designated as
  477. "selected within the frame".  The frame's cursor appears in that
  478. window.  At ant time, one frame is the selected frame; and the window
  479. selected within that frame is "the selected window".  The selected
  480. window's buffer is usually the current buffer (except when `set-buffer'
  481. has been used).  *Note Current Buffer::.
  482.    For practical purposes, a window exists only while it is displayed in
  483. a frame.  Once removed from the frame, the window is effectively deleted
  484. and should not be used, *even though there may still be references to
  485. it* from other Lisp objects.  Restoring a saved window configuration is
  486. the only way for a window no longer on the screen to come back to life.
  487. (*Note Deleting Windows::.)
  488.    Each window has the following attributes:
  489.    * containing frame
  490.    * window height
  491.    * window width
  492.    * window edges with respect to the screen or frame
  493.    * the buffer it displays
  494.    * position within the buffer at the upper left of the window
  495.    * amount of horizontal scrolling, in columns
  496.    * point
  497.    * the mark
  498.    * how recently the window was selected
  499.    Users create multiple windows so they can look at several buffers at
  500. once.  Lisp libraries use multiple windows for a variety of reasons, but
  501. most often to display related information.  In Rmail, for example, you
  502. can move through a summary buffer in one window while the other window
  503. shows messages one at a time as they are reached.
  504.    The meaning of "window" in Emacs is similar to what it means in the
  505. context of general-purpose window systems such as X, but not identical.
  506. The X Window System places X windows on the screen; Emacs uses one or
  507. more X windows as frames, and subdivides them into Emacs windows.  When
  508. you use Emacs on a character-only terminal, Emacs treats the whole
  509. terminal screen as one frame.
  510.    Most window systems support arbitrarily located overlapping windows.
  511. In contrast, Emacs windows are "tiled"; they never overlap, and
  512. together they fill the whole screen or frame.  Because of the way in
  513. which Emacs creates new windows and resizes them, you can't create
  514. every conceivable tiling of windows on an Emacs frame.  *Note Splitting
  515. Windows::, and *Note Size of Window::.
  516.    *Note Display::, for information on how the contents of the window's
  517. buffer are displayed in the window.
  518.  - Function: windowp OBJECT
  519.      This function returns `t' if OBJECT is a window.
  520. File: elisp,  Node: Splitting Windows,  Next: Deleting Windows,  Prev: Basic Windows,  Up: Windows
  521. Splitting Windows
  522. =================
  523.    The functions described here are the primitives used to split a
  524. window into two windows.  Two higher level functions sometimes split a
  525. window, but not always: `pop-to-buffer' and `display-buffer' (*note
  526. Displaying Buffers::.).
  527.    The functions described here do not accept a buffer as an argument.
  528. The two "halves" of the split window initially display the same buffer
  529. previously visible in the window that was split.
  530.  - Command: split-window &optional WINDOW SIZE HORIZONTAL
  531.      This function splits WINDOW into two windows.  The original window
  532.      WINDOW remains the selected window, but occupies only part of its
  533.      former screen area.  The rest is occupied by a newly created
  534.      window which is returned as the value of this function.
  535.      If HORIZONTAL is non-`nil', then WINDOW splits into two side by
  536.      side windows.  The original window WINDOW keeps the leftmost SIZE
  537.      columns, and gives the rest of the columns to the new window.
  538.      Otherwise, it splits into windows one above the other, and WINDOW
  539.      keeps the upper SIZE lines and gives the rest of the lines to the
  540.      new window.  The original window is therefore the left-hand or
  541.      upper of the two, and the new window is the right-hand or lower.
  542.      If WINDOW is omitted or `nil', then the selected window is split.
  543.      If SIZE is omitted or `nil', then WINDOW is divided evenly into
  544.      two parts.  (If there is an odd line, it is allocated to the new
  545.      window.)  When `split-window' is called interactively, all its
  546.      arguments are `nil'.
  547.      The following example starts with one window on a screen that is 50
  548.      lines high by 80 columns wide; then the window is split.
  549.           (setq w (selected-window))
  550.                => #<window 8 on windows.texi>
  551.           (window-edges)          ; Edges in order:
  552.                => (0 0 80 50)     ;   left--top--right--bottom
  553.           ;; Returns window created
  554.           (setq w2 (split-window w 15))
  555.                => #<window 28 on windows.texi>
  556.           (window-edges w2)
  557.                => (0 15 80 50)    ; Bottom window;
  558.                                   ;   top is line 15
  559.           (window-edges w)
  560.                => (0 0 80 15)     ; Top window
  561.      The screen looks like this:
  562.           __________
  563.                   |          |  line 0
  564.                   |    w     |
  565.                   |__________|
  566.                   |          |  line 15
  567.                   |    w2    |
  568.                   |__________|
  569.                                 line 50
  570.            column 0   column 80
  571.      Next, the top window is split horizontally:
  572.           (setq w3 (split-window w 35 t))
  573.                => #<window 32 on windows.texi>
  574.           (window-edges w3)
  575.                => (35 0 80 15)  ; Left edge at column 35
  576.           (window-edges w)
  577.                => (0 0 35 15)   ; Right edge at column 35
  578.           (window-edges w2)
  579.                => (0 15 80 50)  ; Bottom window unchanged
  580.      Now, the screen looks like this:
  581.           column 35
  582.                    __________
  583.                   |   |      |  line 0
  584.                   | w |  w3  |
  585.                   |___|______|
  586.                   |          |  line 15
  587.                   |    w2    |
  588.                   |__________|
  589.                                 line 50
  590.            column 0   column 80
  591.      Normally, Emacs indicates the border between two side-by-side
  592.      windows with a scroll bar (*note Scroll Bars: X Frame Parameters.)
  593.      or `|' characters.  The display table can specify alternative
  594.      border characters; see *Note Display Tables::.
  595.  - Command: split-window-vertically SIZE
  596.      This function splits the selected window into two windows, one
  597.      above the other, leaving the selected window with SIZE lines.
  598.      This function is simply an interface to `split-windows'.  Here is
  599.      the complete function definition for it:
  600.           (defun split-window-vertically (&optional arg)
  601.             "Split current window into two windows, ..."
  602.             (interactive "P")
  603.             (split-window nil (and arg (prefix-numeric-value arg))))
  604.  - Command: split-window-horizontally SIZE
  605.      This function splits the selected window into two windows
  606.      side-by-side, leaving the selected window with SIZE columns.
  607.      This function is simply an interface to `split-windows'.  Here is
  608.      the complete definition for `split-window-horizontally' (except for
  609.      part of the documentation string):
  610.           (defun split-window-horizontally (&optional arg)
  611.             "Split selected window into two windows, side by side..."
  612.             (interactive "P")
  613.             (split-window nil (and arg (prefix-numeric-value arg)) t))
  614.  - Function: one-window-p &optional NO-MINI ALL-FRAMES
  615.      This function returns non-`nil' if there is only one window.  The
  616.      argument NO-MINI, if non-`nil', means don't count the minibuffer
  617.      even if it is active; otherwise, the minibuffer window is
  618.      included, if active, in the total number of windows, which is
  619.      compared against one.
  620.      The argument ALL-FRAMES specifies which frames to consider.  Here
  621.      are the possible values and their meanings:
  622.     `nil'
  623.           Count the windows in the selected frame, plus the minibuffer
  624.           used by that frame even if it lies in some other frame.
  625.     `t'
  626.           Count all windows in all existing frames.
  627.     `visible'
  628.           Count all windows in all visible frames.
  629.     0
  630.           Count all windows in all visible or iconified frames.
  631.     anything else
  632.           Count precisely the windows in the selected frame, and no
  633.           others.
  634. File: elisp,  Node: Deleting Windows,  Next: Selecting Windows,  Prev: Splitting Windows,  Up: Windows
  635. Deleting Windows
  636. ================
  637.    A window remains visible on its frame unless you "delete" it by
  638. calling certain functions that delete windows.  A deleted window cannot
  639. appear on the screen, but continues to exist as a Lisp object until
  640. there are no references to it.  There is no way to cancel the deletion
  641. of a window aside from restoring a saved window configuration (*note
  642. Window Configurations::.).  Restoring a window configuration also
  643. deletes any windows that aren't part of that configuration.
  644.    When you delete a window, the space it took up is given to one
  645. adjacent sibling.  (In Emacs version 18, the space was divided evenly
  646. among all the siblings.)
  647.  - Function: window-live-p WINDOW
  648.      This function returns `nil' if WINDOW is deleted, and `t'
  649.      otherwise.
  650.      *Warning:* Erroneous information or fatal errors may result from
  651.      using a deleted window as if it were live.
  652.  - Command: delete-window &optional WINDOW
  653.      This function removes WINDOW from the display.  If WINDOW is
  654.      omitted, then the selected window is deleted.  An error is signaled
  655.      if there is only one window when `delete-window' is called.
  656.      This function returns `nil'.
  657.      When `delete-window' is called interactively, WINDOW defaults to
  658.      the selected window.
  659.  - Command: delete-other-windows &optional WINDOW
  660.      This function makes WINDOW the only window on its frame, by
  661.      deleting the other windows in that frame.  If WINDOW is omitted or
  662.      `nil', then the selected window is used by default.
  663.      The result is `nil'.
  664.  - Command: delete-windows-on BUFFER &optional FRAME
  665.      This function deletes all windows showing BUFFER.  If there are no
  666.      windows showing BUFFER, it does nothing.
  667.      `delete-windows-on' operates frame by frame.  If a frame has
  668.      several windows showing different buffers, then those showing
  669.      BUFFER are removed, and the others expand to fill the space.  If
  670.      all windows in some frame are showing BUFFER (including the case
  671.      where there is only one window), then the frame reverts to having a
  672.      single window showing another buffer chosen with `other-buffer'.
  673.      *Note The Buffer List::.
  674.      The argument FRAME controls which frames to operate on:
  675.         * If it is `nil', operate on the selected frame.
  676.         * If it is `t', operate on all frames.
  677.         * If it is `visible', operate on all visible frames.
  678.         * 0 If it is 0, operate on all visible or iconified frames.
  679.         * If it is a frame, operate on that frame.
  680.      This function always returns `nil'.
  681. File: elisp,  Node: Selecting Windows,  Next: Cyclic Window Ordering,  Prev: Deleting Windows,  Up: Windows
  682. Selecting Windows
  683. =================
  684.    When a window is selected, the buffer in the window becomes the
  685. current buffer, and the cursor will appear in it.
  686.  - Function: selected-window
  687.      This function returns the selected window.  This is the window in
  688.      which the cursor appears and to which many commands apply.
  689.  - Function: select-window WINDOW
  690.      This function makes WINDOW the selected window.  The cursor then
  691.      appears in WINDOW (on redisplay).  The buffer being displayed in
  692.      WINDOW is immediately designated the current buffer.
  693.      The return value is WINDOW.
  694.           (setq w (next-window))
  695.           (select-window w)
  696.                => #<window 65 on windows.texi>
  697.  - Macro: save-selected-window FORMS...
  698.      This macro records the selected window, executes FORMS in
  699.      sequence, then restores the earlier selected window.
  700.      This macro does not save or restore anything about the sizes,
  701.      arrangement or contents of windows; therefore, if the FORMS change
  702.      them, the change persists.
  703.      Each frame, at any time, has a window selected within the frame.
  704.      This macro only saves *the* selected window; it does not save
  705.      anything about other frames.  If the FORMS select some other frame
  706.      and alter the window selected within it, the change persists.
  707.    The following functions choose one of the windows on the screen,
  708. offering various criteria for the choice.
  709.  - Function: get-lru-window &optional FRAME
  710.      This function returns the window least recently "used" (that is,
  711.      selected).  The selected window is always the most recently used
  712.      window.
  713.      The selected window can be the least recently used window if it is
  714.      the only window.  A newly created window becomes the least
  715.      recently used window until it is selected.  A minibuffer window is
  716.      never a candidate.
  717.      The argument FRAME controls which windows are considered.
  718.         * If it is `nil', consider windows on the selected frame.
  719.         * If it is `t', consider windows on all frames.
  720.         * If it is `visible', consider windows on all visible frames.
  721.         * If it is 0, consider windows on all visible or iconified
  722.           frames.
  723.         * If it is a frame, consider windows on that frame.
  724.  - Function: get-largest-window &optional FRAME
  725.      This function returns the window with the largest area (height
  726.      times width).  If there are no side-by-side windows, then this is
  727.      the window with the most lines.  A minibuffer window is never a
  728.      candidate.
  729.      If there are two windows of the same size, then the function
  730.      returns the window that is first in the cyclic ordering of windows
  731.      (see following section), starting from the selected window.
  732.      The argument FRAME controls which set of windows are considered.
  733.      See `get-lru-window', above.
  734. File: elisp,  Node: Cyclic Window Ordering,  Next: Buffers and Windows,  Prev: Selecting Windows,  Up: Windows
  735. Cyclic Ordering of Windows
  736. ==========================
  737.    When you use the command `C-x o' (`other-window') to select the next
  738. window, it moves through all the windows on the screen in a specific
  739. cyclic order.  For any given configuration of windows, this order never
  740. varies.  It is called the "cyclic ordering of windows".
  741.    This ordering generally goes from top to bottom, and from left to
  742. right.  But it may go down first or go right first, depending on the
  743. order in which the windows were split.
  744.    If the first split was vertical (into windows one above each other),
  745. and then the subwindows were split horizontally, then the ordering is
  746. left to right in the top of the frame, and then left to right in the
  747. next lower part of the frame, and so on.  If the first split was
  748. horizontal, the ordering is top to bottom in the left part, and so on.
  749. In general, within each set of siblings at any level in the window tree,
  750. the order is left to right, or top to bottom.
  751.  - Function: next-window &optional WINDOW MINIBUF ALL-FRAMES
  752.      This function returns the window following WINDOW in the cyclic
  753.      ordering of windows.  This is the window that `C-x o' would select
  754.      if typed when WINDOW is selected.  If WINDOW is the only window
  755.      visible, then this function returns WINDOW.  If omitted, WINDOW
  756.      defaults to the selected window.
  757.      The value of the argument MINIBUF determines whether the
  758.      minibuffer is included in the window order.  Normally, when
  759.      MINIBUF is `nil', the minibuffer is included if it is currently
  760.      active; this is the behavior of `C-x o'.  (The minibuffer window
  761.      is active while the minibuffer is in use.  *Note Minibuffers::.)
  762.      If MINIBUF is `t', then the cyclic ordering includes the
  763.      minibuffer window even if it is not active.
  764.      If MINIBUF is neither `t' nor `nil', then the minibuffer window is
  765.      not included even if it is active.
  766.      The argument ALL-FRAMES specifies which frames to consider.  Here
  767.      are the possible values and their meanings:
  768.     `nil'
  769.           Consider all the windows in WINDOW's frame, plus the
  770.           minibuffer used by that frame even if it lies in some other
  771.           frame.
  772.     `t'
  773.           Consider all windows in all existing frames.
  774.     `visible'
  775.           Consider all windows in all visible frames.  (To get useful
  776.           results, you must ensure WINDOW is in a visible frame.)
  777.     0
  778.           Consider all windows in all visible or iconified frames.
  779.     anything else
  780.           Consider precisely the windows in WINDOW's frame, and no
  781.           others.
  782.      This example assumes there are two windows, both displaying the
  783.      buffer `windows.texi':
  784.           (selected-window)
  785.                => #<window 56 on windows.texi>
  786.           (next-window (selected-window))
  787.                => #<window 52 on windows.texi>
  788.           (next-window (next-window (selected-window)))
  789.                => #<window 56 on windows.texi>
  790.  - Function: previous-window &optional WINDOW MINIBUF ALL-FRAMES
  791.      This function returns the window preceding WINDOW in the cyclic
  792.      ordering of windows.  The other arguments specify which windows to
  793.      include in the cycle, as in `next-window'.
  794.  - Command: other-window COUNT
  795.      This function selects the COUNTth following window in the cyclic
  796.      order.  If count is negative, then it selects the -COUNTth
  797.      preceding window.  It returns `nil'.
  798.      In an interactive call, COUNT is the numeric prefix argument.
  799.  - Function: walk-windows PROC &optional MINIBUF ALL-FRAMES
  800.      This function cycles through all windows, calling `proc' once for
  801.      each window with the window as its sole argument.
  802.      The optional arguments MINIBUF and ALL-FRAMES specify the set of
  803.      windows to include in the scan.  See `next-window', above, for
  804.      details.
  805. File: elisp,  Node: Buffers and Windows,  Next: Displaying Buffers,  Prev: Cyclic Window Ordering,  Up: Windows
  806. Buffers and Windows
  807. ===================
  808.    This section describes low-level functions to examine windows or to
  809. display buffers in windows in a precisely controlled fashion.  *Note
  810. Displaying Buffers::, for related functions that find a window to use
  811. and specify a buffer for it.  The functions described there are easier
  812. to use than these, but they employ heuristics in choosing or creating a
  813. window; use these functions when you need complete control.
  814.  - Function: set-window-buffer WINDOW BUFFER-OR-NAME
  815.      This function makes WINDOW display BUFFER-OR-NAME as its contents.
  816.      It returns `nil'.
  817.           (set-window-buffer (selected-window) "foo")
  818.                => nil
  819.  - Function: window-buffer &optional WINDOW
  820.      This function returns the buffer that WINDOW is displaying.  If
  821.      WINDOW is omitted, this function returns the buffer for the
  822.      selected window.
  823.           (window-buffer)
  824.                => #<buffer windows.texi>
  825.  - Function: get-buffer-window BUFFER-OR-NAME &optional ALL-FRAMES
  826.      This function returns a window currently displaying
  827.      BUFFER-OR-NAME, or `nil' if there is none.  If there are several
  828.      such windows, then the function returns the first one in the
  829.      cyclic ordering of windows, starting from the selected window.
  830.      *Note Cyclic Window Ordering::.
  831.      The argument ALL-FRAMES controls which windows to consider.
  832.         * If it is `nil', consider windows on the selected frame.
  833.         * If it is `t', consider windows on all frames.
  834.         * If it is `visible', consider windows on all visible frames.
  835.         * If it is 0, consider windows on all visible or iconified
  836.           frames.
  837.         * If it is a frame, consider windows on that frame.
  838.  - Function: get-buffer-window-list BUFFER-OR-NAME &optional MINIBUF
  839.           ALL-FRAMES
  840.      This function returns a list of all the windows currently
  841.      displaying BUFFER-OR-NAME.
  842.      The two optional arguments work like the optional arguments of
  843.      `next-window' (*note Cyclic Window Ordering::.); they are *not*
  844.      like the single optional argument of `get-buffer-window'.  Perhaps
  845.      we should change `get-buffer-window' in the future to make it
  846.      compatible with the other functions.
  847.      The argument ALL-FRAMES controls which windows to consider.
  848.         * If it is `nil', consider windows on the selected frame.
  849.         * If it is `t', consider windows on all frames.
  850.         * If it is `visible', consider windows on all visible frames.
  851.         * If it is 0, consider windows on all visible or iconified
  852.           frames.
  853.         * If it is a frame, consider windows on that frame.
  854.